package com.itrident.dialog;

import com.intellij.ide.highlighter.JavaClassFileType;
import com.intellij.ide.highlighter.JavaFileType;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.EditorFactory;
import com.intellij.openapi.editor.ex.util.EditorFacadeImpl;
import com.intellij.openapi.editor.impl.DocumentImpl;
import com.intellij.openapi.editor.impl.EditorComponentImpl;
import com.intellij.openapi.editor.impl.EditorFactoryImpl;
import com.intellij.openapi.editor.impl.EditorImpl;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.psi.JavaCodeFragmentFactory;
import com.intellij.ui.EditorTextField;
import com.intellij.ui.components.JBPanel;
import com.intellij.ui.components.JBScrollBar;
import com.intellij.ui.components.JBScrollPane;
import com.intellij.util.ui.components.JBComponent;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.awt.*;

import static javax.swing.ScrollPaneConstants.*;

/**
 * @author cxx
 * @create 2021-05-08 14:28
 **/
public class CodeDialog extends DialogWrapper {

    private Project project;

    private Editor editor;

    public CodeDialog(Project project) {
        super (project);
        this.project = project;
        init ();
        setOKButtonText ("Save");
    }

    /**
     * Factory method. It creates panel with dialog options. Options panel is located at the
     * center of the dialog's content pane. The implementation can return {@code null}
     * value. In this case there will be no options panel.
     */
    @Override
    protected @Nullable JComponent createCenterPanel() {

        Dere dere = new Dere (null);
        JComponent jComponent = dere.$$$getRootComponent$$$ ();
        return jComponent;
//        JComponent centerPanel = new JBPanel<> ();
//        Dimension dimension = new Dimension (650, 350);
//        centerPanel.setPreferredSize (dimension);
//        editor = EditorFactoryImpl.getInstance ().createEditor (new DocumentImpl (""),project,JavaFileType.INSTANCE,false);
//        editor.getSettings ().setCaretRowShown (true);
//        editor.getSettings ().setLineNumbersShown (true);
//        editor.getSettings ().setAllowSingleLogicalLineFolding (true);
////        editor.getSettings ().set
//        editor.getComponent ().setPreferredSize (dimension);
////        EditorTextField editorTextField = new EditorTextField (new DocumentImpl (""),project, JavaFileType.INSTANCE,false,false);
//
//        centerPanel.add (editor.getComponent ());
//        return centerPanel;
    }

    /**
     * This method is invoked by default implementation of "OK" action. It just closes dialog
     * with {@code OK_EXIT_CODE}. This is convenient place to override functionality of "OK" action.
     * Note that the method does nothing if "OK" action isn't enabled.
     */
    @Override
    protected void doOKAction() {
        String text = editor.getDocument ().getText ();

        super.doOKAction ();
    }



}
